package com.tito.common.util;

//import com.alibaba.fastjson.JSON;
import lombok.experimental.UtilityClass;
import org.springframework.util.StringUtils;
import org.springframework.validation.support.BindingAwareModelMap;

import java.io.IOException;

/**
 * 缓存key工具类
 */
@UtilityClass   //@UtilityClass，为方法添加static，并添加私有构造方法。
public class CacheKeyUtil {

    /**
     * 获取方法参数组成的key
     *
     * @param params 参数数组
     */
    public static String getMethodParamsKey(Object... params) throws IOException {
        if (StringUtils.isEmpty(params)) {
            return "";
        }
        StringBuilder key = new StringBuilder("(");
        for (Object obj : params) {
            if (obj.getClass().equals(BindingAwareModelMap.class)) {
                continue;
            }
            key.append(JsonUtil.toJson(obj).replaceAll("\"", "'"));
        }
        key.append(')');
        return key.toString();
    }

    public  String test(String str) {
        return "str";
    }

    public static void main(String[] args) {
        System.out.println(CacheKeyUtil.test(""));
    }
}
